# # # # # import json
# # # # #
# # # # import re
# # # #
# # # # import requests
# # # # #
# # # # # param = {
# # # # # 	"shop_id":"taobao_100008795",
# # # # # 	"page_index":1,
# # # # # 	"page_size":100,
# # # # # 	"thumbnail":1,
# # # # # 	"keyword":"自动化测试"
# # # # # }
# # # # #
# # # # # head = {
# # # # #     'content-type': 'application/json',
# # # # # }
# # # # # print(type(param))
# # # # import json
# # # #
# # # #
# # # # # from interface.common.headers import Headers
# # # # # headers = Headers().getheader('http://qa-sapi.xxxxxx.com/passport/v11/tenants/qiushi6')
# # # # # #
# # # # # param = {
# # # # #     "id": "qiushi6",
# # # # #     "pageLoginEnabled":True,
# # # # #     "platCode":"taobao",
# # # # #     "idaasFlag":True,
# # # # #     "tenantId": "qiushi6"
# # # # #     }
# # # # # headers = {'Content-Type': 'application/xml'}
# # # # # # headers['Content-Type'] = 'application/json'
# # # # # try:
# # # # #     info = requests.get('http://qa-sapi.xxxxxx.com/passport/v11/tenants/qiushi6',params=param,headers=headers)
# # # # #     print(info.text)
# # # # # except Exception as e:
# # # # #     print(e)
# # # # # f = open('批量会员积分导入.txt','w',encoding='utf-8')
# # # # #
# # # # # for i in range(1000000):
# # # # #     start = '173'
# # # # #     end = +i
# # # # #     end_s = str(end).zfill(8)
# # # # #     phone = start + end_s
# # # # #     plat = str(i)+"导入等级20"
# # # # #     print(phone)
# # # # #
# # # # #     f.write(plat+','+','+phone+','+'大野'+','+','+ ','+ '等级五'+','+str(10)+','+'2021-12-23 12:13:23'+','+','+'\n')
# # # # # f.close()
# # # # # case_sql = "select * from t_m_test where odsa ='safads';,SELECT SAFAS"
# # # # # case_sql = "select p.valid_point,p.total_gain_point,p.updated,u.shop,u.usable_point from lpee_002.t_m_member_point p join lpee_002.t_m_point_record_usable u on u.member_id = p.member_id and u.point_plan_id = p.point_plan_id where p.member_id = 2021062202 and p.point_plan_id = 20210617 and u.plat = 'TAOBAO' and u.sequence = '202106170004';||"
# # # # # if '||' in case_sql:
# # # # #     sql = case_sql.split("||")
# # # # #     for i in sql:
# # # # #         if re.search('select', i, re.IGNORECASE):
# # # # #             print("select", i)
# # # # #         else:
# # # # #             print("sadfas",i)
# # # # # else:
# # # # #     if ('SELECT' or 'select') in case_sql:
# # # # #         print("select====",type(case_sql), case_sql)
# # # # #     else:
# # # # #         print("sadfas===", case_sql)
# # # #
# # # # # !/usr/bin/python3
# # # # #
# # # # # str = 'Python3'
# # # # #
# # # # # print(str)  # 输出字符串
# # # # # print(str[0:-1])  # 输出第一个到倒数第二个的所有字符
# # # # # print(str[0])  # 输出字符串第一个字符
# # # # # print(str[2:5])  # 输出从第三个开始到第五个的字符
# # # # # print(str[2:])  # 输出从第三个开始后的所有字符
# # # # # print(str[1:5:2])  # 输出从第二个开始到第五个且每隔两个的字符
# # # # # print(str * 2)  # 输出字符串两次
# # # # # print(str + '你好')  # 连接字符串
# # # # #
# # # # # print('------------------------------')
# # # # #
# # # # # print('hello\nPython3')  # 使用反斜杠(\)+n转义特殊字符
# # # # # print(r'hello\nPython3')  # 在字符串前面添加一个 r，表示原始字符串，不会发生转义
# # # # #
# # # # # print("下面会空行")
# # # # # print('\n')       # 输出空行
# # # # # print(r'\n')      # 输出 \n
# # # # # !/usr/bin/python3
# # # #
# # # # # input("\n\n按下 enter 键后退出。")
# # # # # import sys; x = 'Python3'; sys.stdout.write(x + '\n')
# # # # # 表达式 = ''
# # # # # if 表达式:
# # # # #    pass
# # # # # elif 表达式:
# # # # #    pass
# # # # # else:
# # # # #    pass
# # # #
# # # # # import sys
# # # # # for i in sys.argv:
# # # # #     print('命令行参数为:',i)
# # # # # print('\n python 路径为',sys.path)
# # # #
# # # # # from sys import argv, path  # 导入特定的成员
# # # # # print('argv:',argv)
# # # # # print('path:', path)  # 因为已经导入path成员，所以此处引用时不需要加sys.path
# # # # # import sys
# # # # #
# # # # # def fibonacci(n): # 生成器函数 - 斐波那契
# # # # #     a, b, counter = 0, 1, 0
# # # # #     while True:
# # # # #         if (counter > n):
# # # # #             return
# # # # #         yield a
# # # # #         a, b = b, a + b
# # # # #         counter += 1
# # # # # f = fibonacci(10) # f 是一个迭代器，由生成器返回生成
# # # # #
# # # # # while True:
# # # # #     try:
# # # # #         print (next(f), end=" ")
# # # # #     except StopIteration:
# # # # #         sys.exit()
# # # import common.info_error as excep
# # #
# # # def resp_check(info, code,respTime):
# # #     '''
# # #     接口自动化断言封装入口
# # #     :param info: 接口响应
# # #     :param code: 预期结果
# # #     :return:
# # #     '''
# # #     if isinstance(info,dict):
# # #         if bool(checkdict(info,code)):
# # #             return excep.assert_info(info, respTime, code)
# # #         else:
# # #             return excep.assert_err_exception(info, respTime, code)
# # #     elif isinstance(info,list):
# # #         if bool(checklist(info,code)):
# # #             return excep.assert_info(info, respTime, code)
# # #         else:
# # #             return excep.assert_err_exception(info, respTime, code)
# # #
# # #
# # # def checklist(info, code):
# # #     '''
# # #     检查列表
# # #     :param info: 接口响应
# # #     :param code: 预期结果
# # #     :return:
# # #     '''
# # #     try:
# # #         for i in code:
# # #             if isinstance(i, str) or isinstance(i, int):
# # #                 if i in info:
# # #                     continue
# # #                 else:
# # #                     return False
# # #             else:
# # #                 for j in info:
# # #                     if isinstance(i, dict):
# # #                         if bool(checkdict(j, i)):
# # #                             break
# # #                         else:
# # #                             return False
# # #                     elif isinstance(i, list):
# # #                         if bool(checklist(j, i)):
# # #                             break
# # #                         else:
# # #                             return False
# # #                     break
# # #                 else:
# # #                     return False
# # #         return True
# # #     except Exception as e:
# # #         return False
# # #
# # #
# # # def checkdict(info, code):
# # #     '''
# # #     检查json
# # #     :param info:接口响应
# # #     :param code: 预期结果
# # #     :return:
# # #     '''
# # #     try:
# # #         for k, v in code.items():
# # #             for k2, v2 in info.items():
# # #                 if k == k2:
# # #                     if isinstance(v2, list):
# # #                         if bool(checklist(v2, v)):
# # #                             break
# # #                         else:
# # #                             return False
# # #                     elif isinstance(v2, dict):
# # #                         if bool(checkdict(v2, v)):
# # #                             break
# # #                         else:
# # #                             return False
# # #                     elif v == v2:
# # #                         break
# # #                     else:
# # #                         return False
# # #                 else:
# # #                     continue
# # #             else:
# # #                 return False
# # #         return True
# # #     except Exception as e:
# # #         return False
# # #
# # # true = True
# # # false = False
# # # null = None
# # # # resp = {"qwe": [100, '101', 102],"code": 1, "data": [{"test": "1", "test2": "2", "test3": "3","data":{"test123":123}},{"test": "1", "test2": "2", "test3": "3","data":{"test123":123}}], "res": "10", "res1": {"q": "10", "w": "11"}}
# # # # code = {"code": 1, "data": [{"test": "1","data":{"test123":123}}],  "res1": {"q": "10"},"res": "10"}
# # # # resp = {"CARD":[{"planId":1,"enabled":true,"cardName":"全渠道卡","shopConfig":[{"shopId":"157263193","platShopId":"157263193","platCode":"TAOBAO","shopName":"0黑色的琴键0"},{"shopId":"201809201497","platShopId":"201809201497","platCode":"OFFLINE","shopName":"洽小门店"},],"omni":false,"cardCategory":true,"remark":"1test卡，勿删除--taobao(真实会员通店铺)+qiakr+youzan11","plugins":[],"menus":[]},{"planId":2,"enabled":false,"cardName":"淘宝单店铺1","shopConfig":[{"shopId":"128611773","platShopId":"128611773","platCode":"TAOBAO","shopName":"emilyty10433"},{"shopId":"101854160","platShopId":"101854160","platCode":"TAOBAO","shopName":"数云小产品"},{"shopId":"100459009","platShopId":"100459009","platCode":"TAOBAO","shopName":"坏脾气_11"}],"omni":false,"cardCategory":true,"remark":"test卡，勿删1111","plugins":[],"menus":[]},{"planId":330201,"enabled":true,"cardName":"拆卡历史数据同步会员卡","shopConfig":[{"shopId":"20210326002","platShopId":"20210326002","platCode":"TAOBAO","shopName":"test测试店铺032602"},{"shopId":"20210326003","platShopId":"20210326003","platCode":"TAOBAO","shopName":"test测试店铺032603"},{"shopId":"2018092015967","platShopId":"2018092015967","platCode":"OFFLINE","shopName":"sjyj_线下店铺"}],"omni":false,"cardCategory":true,"remark":"测试拆卡","plugins":[],"menus":[]},]}
# # # # code = {"CARD":[{"planId":1,"enabled":true,"cardName":"全渠道卡","shopConfig":[{"shopId":"157263193","shopName":"0黑色的琴键0"},],"omni":false,"remark":"1test卡，勿删除--taobao(真实会员通店铺)+qiakr+youzan11","plugins":[],"menus":[]},]}
# # # resp="数据处理完成"
# # # code = { "valid_point": 0, "total_invalidByRefund_point": 20, "invalidByRefund_point": 20 }
# # # print(checkdict(resp, code))
# # import requests
# # from interface.common.headers import Headers
# # try:
# #     url = 'http://qa-sapi.xxxxxx.com/lpee-member-service/platmember/unbind'
# #     data = { "cardPlanId":328, "tenant":"Josbindquery01", "platCode":"JOS", "platId":"test2021080405", "shopId":"2021080401", "partner":"xxxxxx", "sourceType":"SERVICE", "mobile":"18740000005" }
# #     test = requests.put(url,json=data,headers=Headers().getheader(url))
# #
# #     print(test.text)
# # except Exception as e:
# #     print(e)
#
# import hashlib
#
#
# def test(phone, mobile_key, customer_id=None, plat="TAOBAO"):
#     if plat == "JOS":
#         newmobile = mobile_key + customer_id + phone + mobile_key
#         mix_mobile = hashlib.md5(newmobile.encode(encoding='UTF-8')).hexdigest().upper()
#         mix_mobile2 = hashlib.md5(mix_mobile.encode(encoding='UTF-8')).hexdigest()
#         mixMobile = mix_mobile2.upper()
#         return mixMobile
#     else:
#         taobaomobile = 'tmall' + phone + mobile_key
#         mix_mobile = hashlib.md5(taobaomobile.encode(encoding='UTF-8')).hexdigest()
#         mix_mobile2 = hashlib.md5(mix_mobile.encode(encoding='UTF-8')).hexdigest()
#         return mix_mobile2
#
#
# plat = "JOS"
# phone = '17338140001'
# mobilekey = "QWE123"
# customer_id=""
# print(test(phone=phone, mobile_key=mobilekey,customer_id=customer_id))
#
#
# # def jacoco_marathon(service,version):
# #     import requests
# #     data = requests.get(
# #         url=f'https://qa-sapi.xxxxxx.com/provide-host-server/v1/serviceInfo/getIpPort?ServiceName={service}&apiVersion={version}')
# #     res = data.json()
# #     for k, v in res.items():
# #         null = None
# #         if v is not None:
# #             print(k,v)
# #     return True
# #
# # if __name__ == '__main__':
# #     jacoco_marathon("loyalty2-member","v1")
#
import os


def get_file_dir(root):
    '''
    查找目标目录
    :param root:
    :param target:
    :return:
    '''
    java_dir = os.path.join(root, 'src', 'main', 'java')
    class_dir = os.path.join(root, 'target', 'classes')
    if os.path.exists(java_dir) and os.path.exists(class_dir):
        return java_dir, class_dir
    else:
        class_list = []
        java_list = []
        try:
            with os.scandir(root) as dirs:
                for d in dirs:
                    if d.is_dir():
                        new_dir = os.path.join(root, d)
                    else:
                        continue
                    dl = os.listdir(new_dir)
                    if 'target' in dl and 'src' in dl:
                        target_dir = os.path.join(root, d, 'target', 'classes')
                        class_list.append(target_dir)
                        src_dir = os.path.join(root, d, 'src', 'main', 'java')
                        java_list.append(src_dir)
        except Exception as e:
            # log.error(str(e))
            print(e)
            return False, False
        if class_list and java_list:
            if len(class_list) == 1 and len(java_list) == 1:
                return java_list[0], class_list[0]
            elif len(class_list) > 1 and len(java_list) > 1:
                return ','.join(java_list), ','.join(class_list)
            else:
                print('路径查找失败，class文件和java文件不一致')
                return False, False
        else:
            print('未找到指定路径{}'.format(root))
            return False, False

d = '/root/.jenkins/workspace'
service = 'loyalty2-member'
# test = os.path.join(d, service)
# print(test)

print(get_file_dir(os.path.join(d, service)))